package com.morty.config.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

/**
 * @Author: WindyHu
 * @Date: 2021/5/14 11:22
 * @Description:
 */
public class JsonUtil {

	private static final ObjectMapper mapper = new ObjectMapper();

	/**
	 * 对象转字符串
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	public static String objectToString(Object obj) throws Exception {
		return mapper.writeValueAsString(obj);
	}

	/**
	 * map2Bean
	 * @param map
	 * @param clazz
	 * @return
	 * @throws Exception
	 */
	public static Object mapToBean(Map map, Class clazz) throws Exception {
		return mapper.readValue(objectToString(map), clazz);
	}

}
